import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

import 'auth_vm.dart';
import 'common.dart';

class Register extends StatefulWidget {
  const Register({super.key});

  @override
  State<Register> createState() => _RegisterState();
}

class _RegisterState extends State<Register> {
  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (context) => AuthViewModel(),
      child: Scaffold(
        backgroundColor: Colors.teal,
        body: Container(
          padding: EdgeInsets.all(20.0),
          child: Consumer<AuthViewModel>(
            builder: (context, authViewModel, child) {
              return Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  connonInput(labelText: '输入账号', onChanged: (value) => authViewModel.registerInfo.username = value),
                  SizedBox(height: 16.0),
                  connonInput(labelText: '输入密码', onChanged: (value) => authViewModel.registerInfo.password = value),
                  SizedBox(height: 16.0),
                  connonInput(labelText: '确认密码', onChanged: (value) => authViewModel.registerInfo.repassword = value),
                  SizedBox(height: 50.0),
                  commonButton(text: '注册账号', border: true, onPressed: () => authViewModel.register().then((value) {
                    if (value == true) {
                      Navigator.pop(context);
                    }
                  })),
                  SizedBox(height: 5.0),
                  commonButton(text: '返回登录', onPressed: () {
                    Navigator.pop(context);
                  }),
                ],
              );
            },
          ),
        ),
      ),
    );
  }

  
}